package org.example.service.impl;

import javafx.scene.layout.CornerRadii;
import org.example.dao.CourseDao;
import org.example.dto.CurriculumDto;
import org.example.dto.DepartmentDto;
import org.example.dto.MajorDto;
import org.example.pojo.Course;
import org.example.pojo.Department;
import org.example.pojo.Major;
import org.example.service.CurriculumService;
import org.example.utils.Tool;
import org.example.vo.CurriculumVo;
import org.example.vo.DepartmentVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CurriculumServiceImpl implements CurriculumService {
    @Resource
    private CourseDao dao;
    private Tool tool=new Tool();

    private DepartmentVo PoTransToVo(Department department){
        DepartmentVo department1=new DepartmentVo();
        department1.setDepartmentName(department.getDepartname());
        department1.setDepartmentId(department.getDepartno());
        return department1;
    }

    private CurriculumDto PoTransToDto(Course course){
        CurriculumDto curriculumDto=new CurriculumDto();
        curriculumDto.setCurriculumId(course.getCourseno());
        curriculumDto.setCurriculumName(course.getCoursename());
        curriculumDto.setCurriculumType(tool.checkCourseTypeString(course.getType()));
        curriculumDto.setCurriculumCharacteristics(tool.checkCourseTypeString(course.getNature()));
        curriculumDto.setCredit(4);
        return curriculumDto;
    }
    private Course VoTransToPo(CurriculumVo curriculumVo){
        Course course=new Course();
        course.setCourseno(curriculumVo.getCurriculumId());
        course.setCoursename(curriculumVo.getCurriculumName());
        course.setNature(tool.checkCourseNature(curriculumVo.getCurriculumCharacteristics()));
        course.setType(tool.checkCourseTypeint(curriculumVo.getCurriculumType()));
        return course;
    }


    @Override
    public List<CurriculumDto> queryAllCurriculum() {
        List<Course> curriculumList=dao.queryAll();
        List<CurriculumDto> curriculumDtoList=new ArrayList<>();
        for(int i=0;i<curriculumList.size();i++)
            curriculumDtoList.add(i,PoTransToDto(curriculumList.get(i)));
        return curriculumDtoList;
    }

    @Override
    public Integer deleteCurriculum(Integer id) {
        if(dao.delete(id))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer updateCurriculum(CurriculumVo curriculum) {
        if(dao.update(VoTransToPo(curriculum)))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer addCurriculum(CurriculumVo curriculum) {
        if(dao.insert(VoTransToPo(curriculum)))
            return 1;
        else
            return 0;
    }

    @Override
    public Integer countCurriculum_() {
        return dao.queryAll().size();
    }

    @Override
    public CurriculumDto queryCurriculumById_(Integer curriculumId) {
        Course course=new Course();
        course.setCourseno(curriculumId);
        return PoTransToDto(dao.queryByCondition(course).get(0));
    }

    @Override
    public List<CurriculumDto> queryCurriculumByCurriculumCharacteristics(String curriculumCharacteristics) {
        Course course=new Course();
        course.setNature(tool.checkCourseNature(curriculumCharacteristics));
        List<Course> curriculumList=dao.queryByCondition(course);
        List<CurriculumDto> curriculumDtoList=new ArrayList<>();
        for(int i=0;i<curriculumList.size();i++)
            curriculumDtoList.add(i,PoTransToDto(curriculumList.get(i)));
        return curriculumDtoList;
    }

    @Override
    public Integer countCurriculumByCurriculumCharacteristics(String curriculumCharacteristics) {
        Course course=new Course();
        course.setNature(tool.checkCourseNature(curriculumCharacteristics));
        return dao.queryByCondition(course).size();
    }
}
